package com.kyzh.core.activities

import android.graphics.Color
import android.os.Bundle
import android.util.Log
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gushenge.core.base.activity.BaseActivity
import com.gushenge.core.beans.GoldDetail
import com.gushenge.core.requests.UserRequest
import com.kyzh.core.R
import kotlinx.android.synthetic.main.activity_gold_detail.*

class GoldDetailActivity : BaseActivity() {
    private val beans = arrayListOf<GoldDetail>()
    private val adapter = Adapter(R.layout.item_sharehistory,beans)
    private var p = 1
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_gold_detail)
        rvHistory.adapter = adapter

        beans.add(0, GoldDetail(getString(R.string.gold),getString(R.string.paymentMode),getString(R.string.time)))
        adapter.notifyDataSetChanged()
        adapter.loadMoreModule.isEnableLoadMore = true
        adapter.loadMoreModule.preLoadNumber = 4
        adapter.loadMoreModule.isEnableLoadMoreIfNotFullPage = false
        adapter.loadMoreModule.setOnLoadMoreListener {
            initData()
        }
    }

    private fun initData() {
        UserRequest.goldDetail(this,p){ data, p, max ->
            adapter.addData(data)
            this.p = p
            if (p>max){
                adapter.loadMoreModule.loadMoreEnd()
            }else{
                adapter.loadMoreModule.loadMoreComplete()
            }
        }
    }


    private inner class Adapter(layout:Int,beans:ArrayList<GoldDetail>): BaseQuickAdapter<GoldDetail, BaseViewHolder>(layout,beans),LoadMoreModule{
        override fun convert(helper: BaseViewHolder, item: GoldDetail) {
            helper.setText(R.id.tv1,item.time)
                    .setText(R.id.tv2,item.gold)
                    .setText(R.id.tv3,item.note)

            if (helper.layoutPosition==0){
                helper.setBackgroundColor(R.id.tv1, Color.parseColor("#E9F1FF"))
                        .setBackgroundColor(R.id.tv2, Color.parseColor("#E9F1FF"))
                        .setBackgroundColor(R.id.tv3, Color.parseColor("#E9F1FF"))
            }else{
                helper.setBackgroundColor(R.id.tv1, Color.WHITE)
                        .setBackgroundColor(R.id.tv2, Color.WHITE)
                        .setBackgroundColor(R.id.tv3, Color.WHITE)
            }
        }
    }
}